Skip to content

Fix in MISRA rule 6.1 check#3458

Merged
danmar merged 3 commits intocppcheck-opensource:mainfrom
danimartin82:main
Sep 22, 2021
Merged

Fix in MISRA rule 6.1 check#3458
danmar merged 3 commits intocppcheck-opensource:mainfrom
danimartin82:main

Conversation

@danimartin82
Copy link
Copy Markdown
Contributor

@danimartin82 danimartin82 commented Sep 17, 2021

Hi @danmar congrats for cppcheck!!! such a great tool. We are using it and we found some with MISRA rule 6.1.
This is an example of our code:

imagen

and this is the report:

imagen

as you can see, "unsigned int" is being accepted, but "uint16_t" not.

This is the official MIRSA 2012 rule:
imagen

(see in yellow that typedefs shall be accepted)

so I've been debuging your misra.py file......and I did a fix. Now It detects the sign for both conventions ("unsiged int" and "uint")

Thanks!!

Dani

@danimartin82
Copy link
Copy Markdown
Contributor Author

It looks like some checks are failing because the check is testing the 6.1 misra rule. If this PR is accepted....the checks shall be changed aswell

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Sep 17, 2021

Using valuetype is ok. can you please look at the test also. You should be able to run it locally like this:

cd cppcheck/addons/test
~/cppcheck/cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test.c --std=c89 --platform=unix64 && python3 ../misra.py -verify misra/misra-test.c.dump

@danimartin82
Copy link
Copy Markdown
Contributor Author

Any maintainer could please run the pipeline??
Thanks!!

unsigned int a:2; // Compliant
signed int b:2; // Compliant
UINT_TYPEDEF c:2; // Compliant
int d:2; // 6.1 - plain int not compliant
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should warn about this

@danimartin82
Copy link
Copy Markdown
Contributor Author

Hi @danmar I've been reviewing this....understanding the way the tests are done......and my initial fix was not correct, I think. That's why I needed to delete a test to run successfully. Your infraestructure is quite complex.....I'm learning about it. Now I thinks it looks better locally in all the tests that I've achieved to perform. In my local code, this is how it looks like:

imagen

If you could run the pipelines again, please....

Thanks!!!
:-)

@danimartin82
Copy link
Copy Markdown
Contributor Author

From my side it's ready to be merged

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Sep 20, 2021

I would like that you add a line of test code in cppcheck/addons/test/misra/misra-test.c

please tweak the struct struct_with_bitfields with some uint16_t field.

@danimartin82
Copy link
Copy Markdown
Contributor Author

my fault!! I was testing locally only --std=c99, and not --std=c89
Is this the good one?
sorry for the incoveniences @danmar !!

@danmar danmar merged commit f01ffdd into cppcheck-opensource:main Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants